﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
namespace Sbook.Data
{
    public class PublisherController:SqlDataProvider
    {
        #region[Publisher_GetById]
        public List<PublisherInfo> Publisher_GetById(string Id)
        {
            List<Data.PublisherInfo> list = new List<Data.PublisherInfo>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Publisher_GetById", GetConnection()))
            {
                Data.PublisherInfo obj = new Data.PublisherInfo();
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@PId", Id));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.PublisherIDataReader(dr));
                    }
                    dr.Close();
                    //conn.Close();
                }
            }
            return list;
        }
        #endregion
        #region[Publisher_GetByTop]
        public List<PublisherInfo> Publisher_GetByTop(string Top, string Where, string Order)
        {
            List<Data.PublisherInfo> list = new List<Data.PublisherInfo>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Publisher_GetByTop", GetConnection()))
            {
                Data.PublisherInfo obj = new Data.PublisherInfo();
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Top", Top));
                dbCmd.Parameters.Add(new SqlParameter("@Where", Where));
                dbCmd.Parameters.Add(new SqlParameter("@Order", Order));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.PublisherIDataReader(dr));
                    }
                    dr.Close();
                    //conn.Close();
                }
            }
            return list;
        }
        #endregion
        #region[Publisher_GetByAll]
        public List<PublisherInfo> Publisher_GetByAll()
        {
            List<Data.PublisherInfo> list = new List<Data.PublisherInfo>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Publisher_GetByAll", GetConnection()))
            {
                Data.PublisherInfo obj = new Data.PublisherInfo();
                dbCmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.PublisherIDataReader(dr));
                    }
                    dr.Close();
                    //conn.Close();
                }
            }
            return list;
        }
        #endregion
        #region[Publisher_Paging]
        public List<PublisherInfo> Publisher_Paging(string CurentPage, string PageSize)
        {
            List<Data.PublisherInfo> list = new List<Data.PublisherInfo>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Publisher_Paging", GetConnection()))
            {
                Data.PublisherInfo obj = new Data.PublisherInfo();
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@CurentPage", CurentPage));
                dbCmd.Parameters.Add(new SqlParameter("@PageSize", PageSize));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.PublisherIDataReader(dr));
                    }
                    dr.Close();
                    //conn.Close();
                }
            }
            return list;
        }
        #endregion
        #region[Publisher_Insert]
        public bool Publisher_Insert(PublisherInfo data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Publisher_Insert", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@PCode", data.PCode));
                dbCmd.Parameters.Add(new SqlParameter("@PName", data.PName));
                dbCmd.Parameters.Add(new SqlParameter("@PAddress", data.PAddress));
                dbCmd.Parameters.Add(new SqlParameter("@PPhone", data.PPhone));
                dbCmd.Parameters.Add(new SqlParameter("@PFax", data.PFax));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Publisher");
            return true;
        }
        #endregion
        #region[Publisher_Update]
        public bool Publisher_Update(PublisherInfo data)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Publisher_Update", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@PId", data.PId));
                dbCmd.Parameters.Add(new SqlParameter("@PCode", data.PCode));
                dbCmd.Parameters.Add(new SqlParameter("@PName", data.PName));
                dbCmd.Parameters.Add(new SqlParameter("@PAddress", data.PAddress));
                dbCmd.Parameters.Add(new SqlParameter("@PPhone", data.PPhone));
                dbCmd.Parameters.Add(new SqlParameter("@PFax", data.PFax));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Publisher");
            return true;
        }
        #endregion
        #region[Publisher_Delete]
        public bool Publisher_Delete(string Id)
        {
            using (SqlCommand dbCmd = new SqlCommand("sp_Publisher_Delete", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@PId", Id));
                dbCmd.ExecuteNonQuery();
            }
            //Clear cache
            System.Web.HttpContext.Current.Cache.Remove("Publisher");
            return true;
        }
        #endregion
    }
}